using NUnit.Framework;

namespace Solver
{
	/// <summary>
	/// What is the sum of both diagonals in a 1001 by 1001 spiral?
	/// </summary>
	public class Problem028 : SelfChecker, IProblem
	{
		public int Id
		{
			get { return 28; }
		}

		public string Solve()
		{
			return Solve(1001).ToString();
		}

		private static long Solve(int param)
		{
			var s = 1;
			for (var k = 3; k <= param; k += 2)
				s += 4*k*k - 6*(k - 1);
			return s;
		}

		[Test]
		public override void Check()
		{
			Assert.AreEqual(101, Solve(5));
			Assert.AreEqual(669171001, Solve(1001));
		}
	}
}